SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema emma
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `emma` ;
CREATE SCHEMA IF NOT EXISTS `emma` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `emma` ;

-- -----------------------------------------------------
-- Table `emma`.`rol`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`rol` (
  `idrol` INT NOT NULL AUTO_INCREMENT,
  `tipo` VARCHAR(45) NULL,
  PRIMARY KEY (`idrol`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`usuario`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`usuario` (
  `idusuario` INT NOT NULL AUTO_INCREMENT,
  `nombre` VARCHAR(45) NULL,
  `apellido` VARCHAR(45) NULL,
  `fk_rol` INT NULL,
  `estatus` VARCHAR(45) NULL,
  PRIMARY KEY (`idusuario`),
  INDEX `fk_rol_idx` (`fk_rol` ASC),
  CONSTRAINT `fk_rol`
    FOREIGN KEY (`fk_rol`)
    REFERENCES `emma`.`rol` (`idrol`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`grado`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`grado` (
  `idgrado` INT NOT NULL AUTO_INCREMENT,
  `nivel` VARCHAR(45) NULL,
  PRIMARY KEY (`idgrado`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`curso`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`curso` (
  `idcurso` INT NOT NULL AUTO_INCREMENT,
  `nombre` VARCHAR(45) NULL,
  `codigo` VARCHAR(45) NOT NULL,
  `fk_grado` INT NULL,
  PRIMARY KEY (`idcurso`, `codigo`),
  INDEX `fk_grado_idx` (`fk_grado` ASC),
  CONSTRAINT `fk_grado`
    FOREIGN KEY (`fk_grado`)
    REFERENCES `emma`.`grado` (`idgrado`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`tipo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`tipo` (
  `idtipo` INT NOT NULL AUTO_INCREMENT,
  `nombre` VARCHAR(45) NULL,
  PRIMARY KEY (`idtipo`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`nota`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`nota` (
  `idnota` INT NOT NULL AUTO_INCREMENT,
  `fk_tipo` INT NULL,
  `nota` VARCHAR(45) NULL,
  PRIMARY KEY (`idnota`),
  INDEX `fk_tipo_idx` (`fk_tipo` ASC),
  CONSTRAINT `fk_tipo`
    FOREIGN KEY (`fk_tipo`)
    REFERENCES `emma`.`tipo` (`idtipo`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`us_cu`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`us_cu` (
  `idus_cu` INT NOT NULL AUTO_INCREMENT,
  `fk_usuario` INT NULL,
  `fk_curso` INT NULL,
  PRIMARY KEY (`idus_cu`),
  INDEX `fk_usuario_idx` (`fk_usuario` ASC),
  INDEX `fk_curso_idx` (`fk_curso` ASC),
  CONSTRAINT `fk_usuario`
    FOREIGN KEY (`fk_usuario`)
    REFERENCES `emma`.`usuario` (`idusuario`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_curso`
    FOREIGN KEY (`fk_curso`)
    REFERENCES `emma`.`curso` (`idcurso`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`no_us_cu`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`no_us_cu` (
  `idno_us_cu` INT NOT NULL AUTO_INCREMENT,
  `fk_us_cu` INT NULL,
  `fk_nota` INT NULL,
  PRIMARY KEY (`idno_us_cu`),
  INDEX `fk_us_cu_idx` (`fk_us_cu` ASC),
  INDEX `fk_nota_idx` (`fk_nota` ASC),
  CONSTRAINT `fk_us_cu`
    FOREIGN KEY (`fk_us_cu`)
    REFERENCES `emma`.`us_cu` (`idus_cu`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_nota`
    FOREIGN KEY (`fk_nota`)
    REFERENCES `emma`.`nota` (`idnota`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`accion`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`accion` (
  `idaccion` INT NOT NULL AUTO_INCREMENT,
  `nombre` VARCHAR(45) NULL,
  `fecha` TIMESTAMP NULL,
  PRIMARY KEY (`idaccion`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `emma`.`log`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `emma`.`log` (
  `idlog` INT NOT NULL AUTO_INCREMENT,
  `idusuario` INT NULL,
  `idaccion` INT NULL,
  PRIMARY KEY (`idlog`),
  INDEX `fk_accion_idx` (`idaccion` ASC),
  CONSTRAINT `fk_accion`
    FOREIGN KEY (`idaccion`)
    REFERENCES `emma`.`accion` (`idaccion`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
